package com.examination.system.instructor.service.impl; 

import com.examination.framework.model.response.CommonCode;
import com.examination.system.administration.response.AddResult;
import com.examination.system.instructor.dao.mapper.StudentAwardMapper;
import com.examination.system.instructor.dao.mapper.StudentFamilyBackgroundMapper;
import com.examination.system.instructor.dao.mapper.TbStudentEssentialMapper;
import com.examination.system.instructor.dao.mapper.TbStudentFamilyInformationMapper;
import com.examination.system.instructor.service.StudentService;
import com.examination.system.instructor.student.ext.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * @author 寇淇芮
 * @Date 2019/10/14 21:47
 */
@Service
public class StudentServiceImpl extends  EntityRepositoryServiceImpl<TbStudentEssentialMapper, TbStudentEssential>  implements StudentService {
    protected final static Logger log = LoggerFactory.getLogger(StudentServiceImpl.class);

    @Autowired
    private TbStudentFamilyInformationMapper tbStudentFamilyInformationMapper;

    @Autowired
    private StudentFamilyBackgroundMapper studentFamilyBackgroundMapper;

    @Autowired
    private StudentAwardMapper studentAwardMapper;

    @Autowired
    private TbStudentEssentialMapper tbStudentEssentialMapper;

    @Override
    public StudentEnsemble findStudentByIdAll(String id) {
        StudentEnsemble studentEnsemble = new StudentEnsemble();
        studentEnsemble.setTbStudentFamilyInformation(tbStudentFamilyInformationMapper.selectListById(id));
        studentEnsemble.setTbStudentEssential(tbStudentEssentialMapper.selectJsonById(id));
        studentEnsemble.setStudentAward(studentAwardMapper.selectListById(id));
        studentEnsemble.setStudentFamilyBackground(studentFamilyBackgroundMapper.selectListById(id));
        return studentEnsemble;
    }

    @Override
    public AddResult<TbStudentEssential> addEntity(TbStudentEssential entity) {
        //判断数据是否有效
        entity.setId(UUID.randomUUID().toString());
        return baseMapper.saver(entity)>0? new AddResult<TbStudentEssential>(CommonCode.SUCCESS,entity):new AddResult<TbStudentEssential>(CommonCode.FAIL,entity);
    }



}
